/*
 * @Author: 无聊 7989314+Hwz1997@user.noreply.gitee.com
 * @Date: 2025-09-02 21:48:50
 * @LastEditors: 无聊 7989314+Hwz1997@user.noreply.gitee.com
 * @LastEditTime: 2025-10-24 09:45:46
 * @FilePath: \keep_motion_api\controllers\user\healthAssess.controller.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
const { HealthAssess } = require('@/models/user');
const { clearObject } = require('@/utils');

const getAssessments = async (req, res) => {
  try {
    const { user_id, user_name, pageNum, pageSize } = req.query;
    const offset = (pageNum - 1) * pageSize;
    const limit = pageSize;
    const {rows, total} = await HealthAssess.getAssessments(user_id, user_name, offset, limit);
    res.status(200).send({rows, total});
  } catch (error) {
    res.status(500).json({ message: '查询健康评估失败', error });
  }
}
const createAssessment = async (req, res) => {
  try {
    const body = req.body;
    const params = clearObject(body);
    const assessment = await HealthAssess.createAssessment(params);
    res.status(200).send(assessment);
  } catch (error) {
    res.status(500).json({ message: '创建健康评估失败', error });
  }
}
const updateAssessment = async (req, res) => {
  try {
    const { id } = req.params;
    const body = req.body;
    const params = clearObject(body);
    const assessment = await HealthAssess.updateAssessment(id, params);
    res.status(200).send(assessment);
  } catch (error) {
    res.status(500).json({ message: '更新健康评估失败', error });
  }
}
const getStats = async (req, res) => {
  try {
    const { user_id } = req.query;
    const assessment = await HealthAssess.getStats(user_id);
    res.status(200).send(assessment);
  } catch (error) {
    res.status(500).json({ message: '查询健康评估统计失败', error });
  }
}

module.exports = {
  getAssessments,
  createAssessment,
  updateAssessment,
  getStats 
}
